# 硬件开关设置及操作
print('------')
from mpython import *
import network
import config as C
print('SPoF.py')

wifi_ = wifi()

# DIV_sta_ 存储设备功能的状态
DIV_sta_ = {
    'WiFi': 0,  # WiFi 状态
    'Scn': 0,   # 屏幕状态
    'RGB1_': 0,   #第一颗RGB灯
    'RGB2_': 0,   #第二颗RGB灯
    'RGB3_': 0,   #第三颗RGB灯
}

# 控制 WiFi 功能的函数
def wii_con_(Wii_:int):
    if Wii_ == 0:
        DIV_sta_['WiFi'] = 0  # 更新 WiFi 功能状态为关闭
    elif Wii_ == 1:
        try:
            wifi_.connectWiFi(C.wii_nam_, C.wii_pas_)  # 尝试连接 WiFi
            DIV_sta_['WiFi'] = 1  # 更新 WiFi 功能状态为开启
        except:
            DIV_sta_['WiFi'] = 0  # 连接失败时更新 WiFi 功能状态为关闭
            pass

# 控制屏幕功能开关的函数
def scn_sta_(Scn_=0):
    if Scn_ == 0:
        oled.poweroff()  # 关闭屏幕
    elif Scn_ == 1:
        oled.poweron()  # 开启屏幕

# RGB灯开关控制
def rgb_sta_(RGB1_=0, RGB2_=0, RGB3_=0):
    if RGB1_ == 1:
        rgb[0] = (102, 102, 102)
        DIV_sta_['RGB1_'] = 1
    elif RGB1_ == 0:
        rgb.fill( (0, 0, 0) )
        DIV_sta_['RGB1_'] = 0
    if RGB2_ == 1:
        rgb[1] = (102, 102, 102)
        DIV_sta_['RGB2_'] = 1
    elif RGB2_ == 0:
        rgb.fill( (0, 0, 0) )
        DIV_sta_['RGB2_'] = 0
    if RGB3_ == 1:
        rgb[2] = (102, 102, 102)
        DIV_sta_['RGB3_'] = 1
    elif RGB3_ == 0:
        rgb.fill( (0, 0, 0) )
        DIV_sta_['RGB3_'] = 0

def mae_con_(mode=1): #   硬件重启等功能
    if mode == 1:
        machine.reset()
    else:
        pass